package com.finger.userservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.finger.commonutil.helper.JwtHelper;
import com.finger.modelservice.enums.DictEnum;
import com.finger.modelservice.model.user.Patient;
import com.finger.userservice.client.HospClient;
import com.finger.userservice.mapper.PatientMapper;
import com.finger.userservice.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {

    @Autowired
    private HospClient hospClient;


    @Override
    public List<Patient> findAllPatient(String userId) {

        List<Patient> patients = baseMapper.selectList(new QueryWrapper<Patient>().eq("user_id", userId));

        patients.forEach(patient ->{
            this.packParam(patient);
        });

        return patients;
    }

    @Override
    public void packParam(Patient patient) {

        //根据证件类型编码，获取证件类型具体指
        String certificatesTypeString =
                hospClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getCertificatesType());//联系人证件
        //联系人证件类型
        String contactsCertificatesTypeString =
                hospClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(),patient.getContactsCertificatesType());
        //省
        String provinceString = hospClient.getName(patient.getProvinceCode());
        //市
        String cityString = hospClient.getName(patient.getCityCode());
        //区
        String districtString = hospClient.getName(patient.getDistrictCode());
        patient.getParam().put("certificatesTypeString", certificatesTypeString);
        patient.getParam().put("contactsCertificatesTypeString", contactsCertificatesTypeString);
        patient.getParam().put("provinceString", provinceString);
        patient.getParam().put("cityString", cityString);
        patient.getParam().put("districtString", districtString);
        patient.getParam().put("fullAddress", provinceString + cityString + districtString + patient.getAddress());

    }
}
